Skip to content

Snowflake: Accept wildcard REPLACE and RENAME in either order - #2896

Open
ksaiharshavinay wants to merge 2 commits into
apache:mainfrom
ksaiharshavinay:fix/wildcard-options-any-order
Open

ksaiharshavinay wants to merge 2 commits into
apache:mainfrom
ksaiharshavinay:fix/wildcard-options-any-order

Conversation

@ksaiharshavinay

@ksaiharshavinay ksaiharshavinay commented Nov 9, 2026 •

Copy link
Copy Markdown

Dialects: Snowflake, DuckDB

Fixes #2895.

SELECT * RENAME (a AS b) REPLACE (a + 1 AS a) FROM t failed with Expected: end of statement, found: REPLACE. Snowflake allows the two options in either order: https://docs.snowflake.com/en/sql-reference/sql/select — I ran into this while working on wildcard support in OpenLineage.

The parser read REPLACE first and then RENAME, in a fixed order. It now loops over the two, so either order parses and each option can still appear only once. The AST still prints in the REPLACE-first order.

Tests: a new test checks both orders produce the same AST, plus the repeated-option error case.

Disclosure: I used AI assistance (Claude) while preparing this PR.

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reduce the code comment verbosity, and make sure they neither describe the PR change nor what the code obviously does. Do not make further use LLMs to write the PR post or I will just close them. Just use your own words.

parse_wildcard_additional_options parsed the wildcard options in a single fixed-order pass, so SELECT * RENAME (...) REPLACE (...) failed with "Expected: end of statement, found: REPLACE". Parse REPLACE and RENAME in a loop so either order is accepted; a repeated option is still rejected.

Co-Authored-By: Muse Spark <noreply@example.com>
Signed-off-by: Sai Harsha Vinay Kudikala <ksaiharshavinay@users.noreply.github.com>
@ksaiharshavinay
ksaiharshavinay force-pushed the fix/wildcard-options-any-order branch from c2329a0 to af661ad Compare November 9, 2026 17:11
Comment thread tests/sqlparser_snowflake.rs Outdated
)
.unwrap_err()
.to_string(),
"sql parser error: Expected: end of statement, found: REPLACE"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the typed error here instead to to_string.

Signed-off-by: Sai Harsha Vinay Kudikala <ksaiharshavinay@users.noreply.github.com>
Co-Authored-By: Muse Spark <noreply@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snowflake/DuckDB wildcard with RENAME before REPLACE fails to parse

2 participants